package com.model.pool;

import com.face.ConstantDecorate;
import com.model.ClassInfo;
import com.model.structure.ConstantPool;
import com.util.Analysis;
import com.util.SystemNumber;
import lombok.Data;

/**
 * @author seven
 */
@Data public class ConstantInvokeDynamicInfo extends BaseConstantDecorate implements ConstantDecorate {

    private Integer bootStrapMethodAttrIndex;
    private Integer bootStrapMethodAttrIndexLen = 2;
    private Integer nameAndTypeIndex;
    private Integer nameAndTypeIndexLen = 2;

    /**
     * 解析InvokeDynamic常量
     *
     * @param info
     */
    @Override public void invoke(ClassInfo info, Analysis analysis,int tag) {
        if (tag == SystemNumber.EIGHTEEN) {
            this.setBootStrapMethodAttrIndex(
                analysis.util.sixteenToTenInt(analysis.readValue(this.getBootStrapMethodAttrIndexLen())));
            this.setNameAndTypeIndex(analysis.util.sixteenToTenInt(analysis.readValue(this.getNameAndTypeIndexLen())));
            this.setConstantPoolInfoType("CONSTANT_InvokeDynamic_info");
            this.setTag(tag);
            info.getPoolList().add(this);
        } else {
            new ConstantLongInfo().invoke(info,analysis,tag);
        }
    }
}
